package com.dragon.modules.yuegou.service.impl.member;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.modules.yuegou.entity.member.TemplateGradeParamEntity;
import com.dragon.modules.yuegou.mapper.member.TemplateGradeParamMapper;
import com.dragon.modules.yuegou.model.member.TemplateGradeParam;
import com.dragon.modules.yuegou.query.member.TemplateGradeParamQuery;
import com.dragon.modules.yuegou.service.member.TemplateGradeParamService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员卡等级条件参数表 服务实现
 *
 * @author pbuilder generated
 * @date 2021-12-15 11:38:52
 * @version 2.0
 */
@Service("memTemplateGradeParamService")
public class TemplateGradeParamServiceImpl
		extends ServiceImpl<TemplateGradeParamMapper, TemplateGradeParamEntity>
		implements TemplateGradeParamService {

	@Override
	public void saveTemplateGradeParam(String busdId, String templateSetId, String templateGradeId, List<TemplateGradeParam> params) {
		TemplateGradeParamQuery query = new TemplateGradeParamQuery();
		query.setBusdId(busdId);
		query.setTemplateSetId(templateSetId);
		query.setTemplateGradeId(templateGradeId);
		remove(query.toQueryWrapper());

		for(TemplateGradeParam param : params) {
			save(param);
		}
	}

	public TemplateGradeParam getTemplateGradeParam(String templateSetId,String templateGradeId,String memGradeParamId){
		TemplateGradeParamQuery gradeParamQuery = new TemplateGradeParamQuery();
		gradeParamQuery.templateGradeId().eq(templateGradeId);
		gradeParamQuery.templateSetId().eq(templateSetId);
		gradeParamQuery.paramId().eq(memGradeParamId);
		List<TemplateGradeParamEntity> list = baseMapper.selectList(gradeParamQuery.toQueryWrapper());
		if (CollectionUtils.isNotEmpty(list)){
			return new TemplateGradeParam(list.get(0));
		}
		return null;
	}



}